package com.lushu.chapitre1.graphics.controls {
import com.sfdk.graphics.api.ILoadingBar;
import com.sfdk.graphics.core.TextFieldEx;
import com.sfdk.graphics.enums.ColorConstant;

import flash.display.Graphics;
import flash.display.Sprite;

public class LoadingBar extends Sprite implements ILoadingBar {
    private var _loadingTF:TextFieldEx;
    private const _width:int = 125;

    public function LoadingBar() {
        super();

        _loadingTF = new TextFieldEx("Arial-MarronFonce-11");
        _loadingTF.text = "loading";
        _loadingTF.x = (_width - _loadingTF.textWidth) >> 1;
        _loadingTF.y = - _loadingTF.textHeight;

        addChild(_loadingTF);

        var g:Graphics = this.graphics;
        g.clear();
        g.beginFill(ColorConstant.marronFonce, 0.5);
        g.drawRect(0, 5, _width, 12);
        g.endFill();
    }

    public function setValue(value:int):void {
        var done:int = _width * value;
        graphics.clear();
        graphics.beginFill(ColorConstant.marronFonce, 1);
        graphics.drawRect(0, 5, done, 12);
        graphics.endFill();
        graphics.beginFill(ColorConstant.marronFonce, 0.5);
        graphics.drawRect(done, 5, _width - done, 12);
        graphics.endFill();
    }

}
}